package com.ah.hf.config;

import com.ah.hf.common.JacksonObjectMapper;
import com.ah.hf.entity.Employee;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    
    @Override
    //springboot中的静态文件不能直接访问，配置可以访问的路径
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("配置类启动了");
        registry.addResourceHandler("/backend/**").
                addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").
                addResourceLocations("classpath:/front/");
    }

    @Override
    //mvc框架消息转换器
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        log.info("消息转换器");
        //消息转换器
        MappingJackson2HttpMessageConverter messageConverter =
                new MappingJackson2HttpMessageConverter();
        //把我们自己的消息转换器设置进去
        messageConverter.setObjectMapper(new JacksonObjectMapper());
        //设置自定义的消息转换器为第一位，下标为零
        converters.add(0,messageConverter);
    }

}
